/* ==================================================================   
 * Created [2009-4-27 下午11:32:55] by Jon.King 
 * ==================================================================  
 * TSS 
 * ================================================================== 
 * mailTo:jinpujun@hotmail.com
 * Copyright (c) Jon.King, 2009-2012 
 * ================================================================== 
 */

package com.jinhe.tss.core.sso;

import com.jinhe.tss.core.Config;
import com.jinhe.tss.core.exception.BusinessException;
import com.jinhe.tss.core.util.BeanUtil;


/**
 * <p> IdentityTranslatorFactory.java </p>
 * <p>
 * 身份转换对象工厂类
 * </p>
 */
public class IdentityTranslatorFactory {
    /**
     * 用户身份转换器
     */
    protected static IdentityTranslator translator = null;

    /**
     * <p>
     * 获取身份转换对象
     * </p>
     * @return
     */
    public static IdentityTranslator getTranslator() {
        if (translator == null) {
            String translatorClassName = Config.getAttribute(SSOConstants.IDENTITY_TRANSLATOR);
            if (translatorClassName != null) {
                translator = (IdentityTranslator) BeanUtil.newInstanceByName(translatorClassName);
            } else {
                throw new BusinessException("当前系统没有定义默认身份转换器，用户不能实现单点登录");
            }
        }
        return translator;
    }
}
